package com.ziven.common.widget.alphabet;

import android.icu.text.Transliterator;
import android.os.Build;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

@RequiresApi(api = Build.VERSION_CODES.Q)
class SystemToPinyin extends AbstractToPinyin {

    private Transliterator transliterator;

    private Transliterator get() {
        if(transliterator == null) {
            transliterator = Transliterator.getInstance("Han-Latin/Names;Latin-Ascii;Any-Upper");
        }
        return transliterator;
    }

    @NonNull
    @Override
    public String toPinyin(char indexAlphabet) {
        return get().transliterate(Character.toString(indexAlphabet));
    }
}
